/*****************************************************************************/
/**
 *	\file	check_in.cpp
 *	\author	Xavier
 *	\date	2023/05/07
 *	\version	1.0
 *	\brief	入住实现
 *	\note	Copyright (c) 2020-2030 南京理工大学
 *	\remarks	无
 ******************************************************************************/
#include "head.h"

void checkIn(CMgr *mgrobj)
{
    assert(NULL != mgrobj);
    char name1[10], id1[19];
    int order_state, prepaid;
    cout << "该顾客订房了吗? (1->订了  2->没订) ";
    order_state = inputINT();
    if (order_state == 1)
    {
        cout << "请输入顾客的姓名:" << endl;
        inputStr(name1, sizeof(name1));
    Again005:
        cout << "请输入顾客的身份证号码:" << endl;
        inputStr(id1, sizeof(id1));
        if (strlen(id1) != 18)
        {
            cout << "id should len 18,input again" << endl;
            goto Again005;
        }
        for (int j = 0; j <= mgrobj->i; j++)
        {
            if ((strcmp(mgrobj->customer[j]->get_name(), name1) == 0) && (strcmp(mgrobj->customer[j]->get_ID(), id1) == 0))
            {                                                     // 查找该顾客的定房信息
                int num = mgrobj->customer[j]->get_room_number(); // 取得定房的房间号
                cout << "顾客" << name1 << "今天入住本宾馆! 房间号码为: " << num << endl;
                switch (num / 100)
                {
                case 6:
                    prepaid = mgrobj->customer[j]->get_day() * 150;
                    mgrobj->customer[j]->set_prepaid(prepaid);
                    cout << "请收房费 " << prepaid << "元整!" << endl; // 开始收费
                    mgrobj->room[num % 100 - 1].state = 2;             // 修改房间状态为入住状态
                    break;
                case 7:
                    prepaid = mgrobj->customer[j]->get_day() * 200;
                    mgrobj->customer[j]->set_prepaid(prepaid);
                    cout << "请收房费 " << prepaid << "元整!" << endl;
                    mgrobj->room[19 + num % 100].state = 2;
                    break;
                case 8:
                    prepaid = mgrobj->customer[j]->get_day() * 300;
                    mgrobj->customer[j]->set_prepaid(prepaid);
                    cout << "请收房费 " << prepaid << "元整!" << endl;
                    mgrobj->room[39 + num % 100].state = 2;
                    break;
                case 9:
                    prepaid = mgrobj->customer[j]->get_day() * 600;
                    mgrobj->customer[j]->set_prepaid(prepaid);
                    cout << "请收房费 " << prepaid << "元整!" << endl;
                    mgrobj->room[59 + num % 100].state = 2;
                    break;
                }
                break;
            }
        }
    }
    else
    {
        mgrobj->customer[mgrobj->i] = new Customer;
        int room_standard, day;
        cout << "请您选择预定房间的标准:\n";
        cout << "1.单人间   150元/天\n2.双人间  200元/天\n3.标准间  300元/天\n4.总统套房    600元/天\n";
        room_standard = inputINT();
        cout << "请输入住宿天数\n";
        day = inputINT();
        mgrobj->customer[mgrobj->i]->set_day(day);
        switch (room_standard)
        {
            int n;
        case 1:
            prepaid = day * 150;
            mgrobj->customer[mgrobj->i]->set_prepaid(prepaid);
            cout << "请收房费 " << prepaid << "元整!\n";
            for (n = 0; n < 20; n++)
            {
                if (mgrobj->room[n].state == 0)
                {
                    cout << "入住房间号码为: " << mgrobj->room[n].number << endl;
                    mgrobj->room[n].state = 2;
                    mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                    break;
                }
            }
            break;
        case 2:
            prepaid = day * 200;
            mgrobj->customer[mgrobj->i]->set_prepaid(prepaid);
            cout << "请收房费 " << prepaid << "元整!\n";
            for (n = 20; n < 40; n++)
            {
                if (mgrobj->room[n].state == 0)
                {
                    cout << "入住房间号码为: " << mgrobj->room[n].number << endl;
                    mgrobj->room[n].state = 2;
                    mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                    break;
                }
            }
            break;
        case 3:
            prepaid = day * 300;
            mgrobj->customer[mgrobj->i]->set_prepaid(prepaid);
            cout << "请收房费 " << prepaid << "元整!\n";
            for (n = 40; n < 60; n++)
            {
                if (mgrobj->room[n].state == 0)
                {
                    cout << "入住房间号码为: " << mgrobj->room[n].number << endl;
                    mgrobj->room[n].state = 2;
                    mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                    break;
                }
            }
            break;
        case 4:
            prepaid = day * 600;
            mgrobj->customer[mgrobj->i]->set_prepaid(prepaid);
            cout << "请收房费 " << prepaid << "元整!\n";
            for (n = 60; n < 80; n++)
            {
                if (mgrobj->room[n].state == 0)
                {
                    cout << "入住房间号码为: " << mgrobj->room[n].number << endl;
                    mgrobj->room[n].state = 2;
                    mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                    break;
                }
            }
            break;
        }
        mgrobj->i++;
    }
}